package com.medical.Controller.admin;

import com.medical.DTO.EmployeeDTO;
import com.medical.DTO.EmployeePageDTO;
import com.medical.Service.EmployeeService;
import com.medical.result.PageResult;
import com.medical.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin("*")
@RequestMapping("/api/admin")
@Tag(name = "员工管理类")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /*
     * 新增员工
     */
    @PostMapping("/addEmployee")
    @Operation(summary = "新增员工")
    public Result addEmployee(@RequestBody EmployeeDTO employee)
    {
        log.info("新增员工，员工数据：{}", employee);
        employeeService.addEmployee(employee);
        return Result.success();
    }

    /*
     * 删除员工
     */
    @DeleteMapping("/deleteEmployee/{ids}")
    @Operation(summary = "删除员工")
    public Result deleteEmployee(@PathVariable List<Integer> ids)
    {
        log.info("删除员工，员工id：{}", ids);
        employeeService.deleteEmployee(ids);
        return Result.success();
    }

    /*
     * 修改员工
     */
    @PutMapping("/updateEmployee")
    @Operation(summary = "修改员工")
    public Result updateEmployee(@RequestBody EmployeeDTO employee)
    {
        log.info("修改员工，员工数据：{}", employee);
        employeeService.updateEmployee(employee);
        return Result.success();
    }

    /*
     * 获取员工列表
     */
    @GetMapping("/getEmployeeList")
    @Operation(summary = "获取员工列表")
    public Result getEmployeeList(EmployeePageDTO employeePage)
    {
        log.info("获取员工列表，员工数据：{}", employeePage);
       PageResult page= employeeService.page(employeePage);
        return Result.success(page);
    }

}
